<template>

    <a-spin tip="正在保存指纹..."
            :spinning="spinning"
            style="background-color: #ececec; padding: 10px;">
        <a-row :gutter="16">
            <a-col :span="14">
                <a-card title="指纹表单" :bordered="false">
                    <a-form-model ref="ruleForm" :model="form" :label-col="labelCol"
                                  :wrapper-col="wrapperCol">

                        <a-form-model-item label="指纹名称" prop="fingerCode" ref="fingerCode">
                            <a-select v-model="form.fingerCode"
                                      placeholder="请选择指纹名称"
                                      allowClear
                            >
                                <a-select-option v-for="(item,index) in FingerCodeOPT" :key="index" :value="item.value">
                                    {{item.label}}
                                </a-select-option>
                            </a-select>
                        </a-form-model-item>

                        <a-form-model-item :wrapper-col="{ span: 18, offset: 6 }">


                            <a-button block :size="'large'" type="primary" @click="getFinger()" class="margin-b-1rem"
                            >

                                点击采集指纹
                            </a-button>

                        </a-form-model-item>


                    </a-form-model>


                </a-card>
            </a-col>
            <a-col :span="10">
                <a-card title="采集说明" :bordered="false">

                    <p>1. 确保当前电脑已连接指纹采集器</p>

                    <p>2. 为保证指纹的准确性 指纹采集时 请对同一个指头进行5次以上的取样</p>

                    <p>3.指纹取样完成以后 请保存指纹</p>

                </a-card>
            </a-col>
        </a-row>
{{spinning}}
    </a-spin>

</template>
<script>
    import {ShenyaBrowser} from '@/util/shenya.browser'
    import {dictLoad} from '../../../util/internal.api';
    import {saveStaffFinger} from "../public/http";

    export default {
        props: ["staffCode"],
        data() {
            return {




                FingerCodeOPT: [], //允许采集的指头名称
                form: {
                    staffCode: this.staffCode,
                    fingerCode: null, //指纹名称
                    fingerTxt: null,       //指纹文本
                },
                labelCol: {
                    xs: {
                        span: 24
                    },
                    sm: {
                        span: 6
                    }
                },
                wrapperCol: {
                    xs: {
                        span: 24
                    },
                    sm: {
                        span: 18
                    }
                },


            }
                ;
        },
        methods: {



            getFinger() {
                this.$store.commit("setFingerBase64", "");
                if (this.form.fingerCode === null) {
                    this.$notification.error({message: '采集失败', description: '请选择要采集的指纹名称'});
                    return false;
                }
                try {
                    new ShenyaBrowser(qt.webChannelTransport, function (channel) {
                        return channel.objects.bridge.slot_show_fingerprint()

                    })
                } catch (e) {
                    this.$notification.error({message: '采集失败', description: "请在指纹浏览器内打执行采集程序"});
                }


            },

            //数据初始化
            async init() {

                //指纹名称选徐昂
                await dictLoad('FingerCode').then(res => (this.FingerCodeOPT = res));
            },


        }
        ,
        created() {
            this.init();

        },

        computed: {
            spinning() {
                if (this.$store.getters.hasFinger) {
                    this.form.fingerTxt = this.$store.state.FingerBase64;
                    saveStaffFinger(this.form).then(res => {
                        this.$store.commit("setFingerBase64", "");
                        if (res.code === 0) {
                            this.$notification.success({
                                message: '操作成功',
                                description: res.message
                            });
                            this.form.fingerTxt = null;
                            this.form.fingerCode = null;

                            this.$emit('reloadModal', {render: true});
                        }
                    });

                    return true;

                }
                return false;
            }
        },

        mounted() {window.vue = this}
    }
</script>

